package cn.shengchao.examstar.pay.model.service.fy.request;

import cn.shengchao.examstar.pay.model.service.fy.dto.ParameterCollection;

import java.util.Map;

public class UrlParameterRequest extends BaseFuYouRequest {
    // This field is transient to prevent BaseFuYouRequest from trying to serialize it directly
    // if it were to use a generic field iteration that doesn't check for specific collection types.
    // However, the current BaseFuYouRequest converts fields to strings, so a ParameterCollection field
    // would be mishandled. Thus, we override toParameterCollection.
    private transient ParameterCollection parameters = new ParameterCollection();

    public UrlParameterRequest() {}

    public UrlParameterRequest(Map<String, String> paramsMap) {
        if (paramsMap != null) {
            paramsMap.forEach(parameters::add);
        }
    }

    public void addParameter(String name, String value) {
        parameters.add(name, value);
    }

    // Override to ensure this specific collection is returned,
    // instead of BaseFuYouRequest trying to reflect on its 'parameters' field.
    @Override
    public ParameterCollection toParameterCollection() {
        return parameters;
    }
}